<template>
  <section>
    <div id="u0" class="ax_default">
      <img id="u0_img" class="img" src="../assets/xp1.png" />
    </div>
    <div id="u1" class="ax_default shape">
      <img id="u1_img" class="img" src="../assets/xp3.png" />
    </div>
    <div id="u2">
      <div class="login">
        <div class="login-box"></div>
        <div class="login-main">
          <h1>登 陆</h1>
          <div class="inputBox">
            <label for="username">账号:</label>
            <input type="text" v-model="userName" name="username" id="username" v-focus />
            <br />
            <label for="password">密码:</label>
            <input type="password" v-model="passWord" name="password" id="password" />
          </div>
          <div class="rebmima">
            <label for="remember">
              <input type="checkbox" @click="rebclick" :checked="isreb" id="remember" />记住密码
            </label>
            <label for>忘记密码？</label>
          </div>
          <button class="loginBtn" @click="handleLogin">立即登陆</button>
        </div>
      </div>
    </div>
    <div id="u15" class="ax_default box_2">
      <img id="u15_img" class="img" src="../assets/xp2.png" />
      <div
        id="u15_text"
        class="text"
        style="left: 2px; width: 63px; top: 22px; transform-origin: 31.5px 9.5px;"
      >
        <p>
          <span>logo</span>
        </p>
      </div>
    </div>
  </section>
</template>

<script>
export default {
  name: "Login",
  // 自动聚焦
  directives: {
    focus: {
      inserted: function (el) {
        el.focus();
      },
    },
  },
  computed: {
    // 是否记住密码
    isreb: {
      get() {
        // 也是用了Vuex里的 modules 大家可以当成普通的变量来看
        return this.$store.state.isReb;
      },
      set(newVal) {
        this.$store.commit("handleVal", newVal);
      },
    },
  },
  data() {
    return {
      userName: "",
      passWord: "",
    };
  },
  methods: {
    // 登录
    rebclick() {
      if (this.$store.state.isReb) {
        localStorage.setItem("loginRemb", "1");
      } else {
        localStorage.setItem("loginRemb", null);
      }
    },
    handleLogin() {
      if (this.userName == "" || this.passWord == "") {
        alert("输入框不能为空");
        return;
      }
      // 发送请求
      this.$axios
        .get("/app/mock/264777/example/1598250282719")
        .then((res) => {
          //遍历请求回来的数据查看是否登录正确
          this.$store.state.islogin = false;
          for (let item of res) {
            if (
              item.username == this.userName &&
              item.password == this.passWord
            ) {
              this.$store.state.islogin = true;
            }
          }
          // 密码是否正确
          if (this.$store.state.islogin) {
            localStorage.setItem("loginName", this.userName);
            this.$router.replace("home");
          } else {
            alert("账号或密码错误,请重新登录");
            this.userName = "";
            this.passWord = "";
          }
        })
        .catch((err) => console.log(err));
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>

<style scoped>
#u0_img {
  border-width: 0px;
  position: absolute;
  left: 0px;
  top: 0px;
  width: 100%;
  height: 900px;
}
#u1 {
  border-width: 0px;
  position: absolute;
  left: 0px;
  top: 0px;
  width: 100%;
  height: 900px;
  opacity: 0.5;
}
#u2 {
  border-width: 0px;
  position: absolute;
  left: 0px;
  top: 0px;
  width: 0px;
  height: 0px;
  font-family: "ArialMT", "Arial";
  font-weight: 400;
  font-style: normal;
  font-size: 13px;
  color: #333333;
  text-align: center;
  line-height: normal;
}
#u1_img {
  border-width: 0px;
  position: absolute;
  left: 0px;
  top: 0px;
  width: 100%;
  height: 900px;
}
.ax_default {
  font-family: "ArialMT", "Arial";
  font-weight: 400;
  font-style: normal;
  font-size: 13px;
  color: #333333;
  text-align: center;
  line-height: normal;
}
#u15 {
  border-width: 0px;
  position: absolute;
  left: 25px;
  top: 25px;
  width: 67px;
  height: 63px;
  font-family: "PingFang-SC-Regular", "PingFang SC";
  font-weight: 400;
  font-style: normal;
  font-size: 14px;
  color: #ffffff;
}
#u15_text {
  border-width: 0px;
  position: absolute;
  left: 2px;
  top: 23px;
  width: 63px;
  word-wrap: break-word;
}
.login {
  border-width: 0px;
  position: absolute;
  left: 442px;
  top: 238px;
  width: 556px;
  height: 446px;
}
.login-box {
  width: 100%;
  height: 100%;
  background: inherit;
  background-color: rgba(0, 0, 0, 1);
  opacity: 0.5;
  border-radius: 20px;
}
.login-main {
  position: absolute;
  left: 0px;
  top: 0px;
  width: 556px;
  height: 446px;
  -moz-box-shadow: none;
  -webkit-box-shadow: none;
  box-shadow: none;
}
.login-main h1 {
  margin-top: 20px;
  font-weight: 400;
  font-size: 28px;
  color: #ffffff;
}
.inputBox {
  margin-top: 40px;
}
.inputBox label {
  color: #ffffff;
  font-size: 20px;
}
.inputBox input {
  margin-bottom: 20px;
  width: 348px;
  height: 43px;
  background: inherit;
  background-color: rgba(255, 255, 255, 1) !important;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  padding-left: 10px;
}
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  display: inline-block;
  text-align: center;
  vertical-align: top;
  line-height: 16px;
  margin-right: 10px;
  position: relative;
}

input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  background: #fff;
  width: 100%;
  height: 100%;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
}

input[type="checkbox"]:checked::before {
  content: "\2713";
  background-color: #fff;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  border: 1px solid #7d7d7d;
  border-radius: 4px;
  color: #7d7d7d;
  font-size: 16px;
  font-weight: bold;
}
.rebmima {
  width: 350px;
  height: 20px;
  line-height: 20px;
  margin-left: 130px;
}
.rebmima label {
  float: left;
  color: #ffffff;
  font-size: 14px;
  cursor: pointer;
}
.rebmima label:nth-of-type(2) {
  float: right;
  cursor: pointer;
}
.loginBtn {
  margin-top: 90px;
  border-width: 0px;
  outline: none;
  width: 153px;
  height: 43px;
  background: inherit;
  background-color: rgba(248, 17, 17, 0.8);
  border: none;
  border-radius: 5px;
  -moz-box-shadow: none;
  -webkit-box-shadow: none;
  box-shadow: none;
  font-family: "PingFang-SC-Regular", "PingFang SC";
  font-weight: 400;
  font-style: normal;
  font-size: 20px;
  color: #ffffff;
  transition: all 0.5s;
}
.loginBtn:hover {
  background-color: rgba(255, 0, 0, 1);
}
</style>